<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="4" :sm="24">
              <a-form-item>
                <a-input placeholder="请输入商品名称" v-model="queryParam.name" />
              </a-form-item>
            </a-col>
            <a-col :md="4" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="handleSearch(true)" icon="search">查询</a-button>
              </span>
            </a-col>
            <a-col :md="1" :sm="24" :offset="14">
              <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        showPagination="auto"
        :pagination="pagination"
      >
        <template slot="img_url" slot-scope="text">
          <a-avatar shape="square" :size="64" icon="bank" :src="text" style="width:110px;height:62px" />
        </template>
        <template slot="img_url_two" slot-scope="text">
          <a-avatar shape="square" :size="64" icon="bank" :src="text" style="width:110px;height:62px" />
        </template>
        <template slot="img_url_thire" slot-scope="text">
          <a-avatar shape="square" :size="64" icon="bank" :src="text" style="width:110px;height:62px" />
        </template>
        <a-tag :color="text == 1 ? 'blue' : 'red'" slot="status" slot-scope="text">{{ text | statusFilter }}</a-tag>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="handleEdit(record)">编辑</a>
            <a-divider type="vertical" />
            <a @click="handleDelete(record)">删除</a>
          </template>
        </span>
      </s-table>

      <create-form
        ref="createModal"
        title="家政类型"
        :addAction="addAction"
        :editAction="editAction"
        @ok="handleSearch"
      />
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { houseKindsList, houseKindsDel, houseKindsAdd, houseKindsEdit } from '@/api/house'
import formTableMixin from '@/mixins/formTableMixin'
import CreateForm from '@/views/appliance/modules/applianceForm'

const columns = [
  {
    title: '名称',
    dataIndex: 'name'
  },
  {
    title: '描述',
    dataIndex: 'content',
    scopedSlots: { customRender: 'content' }
  },
  {
    title: '主图',
    dataIndex: 'img_url',
    scopedSlots: { customRender: 'img_url' }
  },
  {
    title: '次图1',
    dataIndex: 'img_url_two',
    scopedSlots: { customRender: 'img_url_two' }
  },
  {
    title: '次图2',
    dataIndex: 'img_url_thire',
    scopedSlots: { customRender: 'img_url_thire' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '150px',
    scopedSlots: { customRender: 'action' }
  }
]

const STATUS = {
  1: '是',
  0: '否'
}

export default {
  name: 'HouseKinds',
  mixins: [formTableMixin],
  components: {
    CreateForm
  },
  data () {
    this.columns = columns
    this.listAction = houseKindsList
    this.delAction = houseKindsDel
    this.editAction = houseKindsAdd
    this.addAction = houseKindsEdit
    return {}
  },
  filters: {
    statusFilter (key) {
      return STATUS[key]
    }
  },
  methods: {}
}
</script>
